/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
// export const twoSum = function(nums, target) {
//   const map = new Map()
//   for (let i = 0; i < nums.length; i++) {
//     const n = nums[i]
//     const diff = target - n
//     if (map.has(diff)) {
//       console.log( [map.get(diff), i])
//       return [map.get(diff), i]
//     }
//     map.set(n, i)
//   }
// };

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
export const twoSum = function (nums, target) {
  const map = new Map()
  for (let i = 0; i < nums.length; i++) {
    if (map.has(nums[i])) {
      return [map.get(nums[i]), i]
    }
    map.set(target - nums[i], i)
  }
}
